package org.bw.bookstore.book.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.bw.bookstore.book.service.MemberService;
import org.bw.bookstore.common.entity.TbUserInfo;
import org.bw.bookstore.common.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description:会员
 * @Author: 范欣宜
 * @Date: 2020/10/22 11:44
 **/

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/member")
@Api(tags = "接口-会员管理")
public class MemberController {

    @Autowired
    private MemberService memberService;


    /**
     * TODO 范欣宜 查询全部会员
     * @Author: 范欣宜
     * @Date: 2020/10/28 18:45
     * @return: com.bw.servercommon.utils.ResponseResult
     **/
    @ApiOperation(value = "查询全部会员", notes = "查询全部会员")
    @PostMapping("/getMember")
    public ResponseResult getMember(){
        return memberService.getMember();
    }

    @ApiOperation(value = "根据id查询会员", notes = "根据id查询会员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "会员id", dataType = "Integer", required = true)
    })
    @GetMapping("/getMemberById")
    public ResponseResult getMemberById(Integer id){
        return memberService.getMemberById(id);
    }

    /**
     * TODO 范欣宜 分页查询全部会员
     * @Author: 范欣宜
     * @Date: 2020/10/28 18:45
     * @param currentPage: 当前页
     * @param pageSize: 每页多少条
     * @return: com.bw.servercommon.utils.ResponseResult
     **/
    @ApiOperation(value = "分页查询全部会员", notes = "分页查询全部会员")
    @PostMapping("/getMemberByPage")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="currentPage", value = "当前页", dataType = "Integer", required=true,example = "0"),
            @ApiImplicitParam(name="pageSize", value = "每页多少条", dataType = "Integer", required=true,example = "0")
    })
    public ResponseResult getMemberByPage(@RequestParam("currentPage") Integer currentPage,
                                          @RequestParam("pageSize") Integer pageSize){
        return memberService.getMemberByPage(currentPage,pageSize);
    }

    @ApiOperation(value = "删除会员", notes = "删除会员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "会员id", dataType = "Integer", required = true)
    })
    @PostMapping("/delMember")
    public ResponseResult delMember(Integer id){
        return memberService.delMember(id);
    }

    /**
     * TODO 范欣宜 刷脸验证
     * 根据用户的面包照片url进行刷脸验证
     * @Author: 范欣宜
     * @Date: 2020/10/20 8:52
     * @param humanFace: 用户信息(面部照片url)
     * @return: com.bw.wisdom_bookstore.entity.ResponseResult
     **/
    @PostMapping("faceVerify")
    @ApiOperation(value="刷脸验证", notes="刷脸验证")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "humanFace", value = "面部照片url",dataType = "String",required = true)
    })
    public ResponseResult faceVerify(String humanFace){

        return memberService.faceVerify(humanFace);
    }

    /**
     * TODO 范欣宜 生成二维码
     * @Author: 范欣宜
     * @Date: 2020/10/20 8:54
     * @param mobile: 手机号
     * @return: com.bw.common.utils.ResponseResult
     **/
    @PostMapping("generateCode")
    @ApiOperation(value = "生成二维码", notes = "生成二维码")
    public ResponseResult generateCode(String mobile){
        return memberService.generateCode(mobile);

    }

    @PostMapping("analysisCode")
    @ApiOperation(value = "解析二维码", notes = "解析二维码")
    public ResponseResult analysisCode(String qrCodeUrl){
        return memberService.analysisCode(qrCodeUrl);

    }


    /**
     * TODO 范欣宜 扫码验证
     * @Author: 范欣宜
     * @Date: 2020/10/20 8:54
     * @param mobile: 手机号
     * @return: com.bw.common.utils.ResponseResult
     **/

    @PostMapping("scanCodeVerify")
    @ApiOperation(value="扫码验证", notes="扫码验证")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mobile", value = "手机号",dataType = "String",required = true)
    })
    public ResponseResult scanCodeVerify(String mobile){

        return memberService.scanCodeVerify(mobile);
    }



    /**
     * TODO 范欣宜 手机号注册
     * @Author: 范欣宜
     * @Date: 2020/10/21 19:42
     * @param mobile: 手机号
     * @param verification: 验证码
     * @return: com.bw.common.utils.ResponseResult
     **/

    @PostMapping("phoneRegister")
    @ApiOperation(value="手机号注册", notes="手机号注册")
    public ResponseResult phoneRegister(String mobile, String verification){

        return memberService.phoneRegister(mobile,verification);
    }

    /**
     * TODO 范欣宜 添加会员
     * @Author: 范欣宜
     * @Date: 2020/10/21 19:42
     * @param userInfo: 会员信息
     * @return: com.bw.common.utils.ResponseResult
     **/

    @PostMapping("staffMemberRegister")
    @ApiOperation(value="添加会员", notes="添加会员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "age", value = "年龄", dataType = "int", required = false),
            @ApiImplicitParam(name = "sex", value = "性别", dataType = "int", required = false),
            @ApiImplicitParam(name = "email", value = "邮箱", dataType = "string", required = false),
            @ApiImplicitParam(name = "mobile", value = "会员手机号", dataType = "string", required = false),
            @ApiImplicitParam(name = "humanFaceUrl", value = "面部url", dataType = "string", required = false),
            @ApiImplicitParam(name = "idCard", value = "身份证号", dataType = "string", required = false),
            @ApiImplicitParam(name = "memberCode", value = "会员码", dataType = "string", required = false),
            @ApiImplicitParam(name = "userPass", value = "密码", dataType = "string", required = false),
            @ApiImplicitParam(name = "realName", value = "会员真实姓名", dataType = "string", required = false),
            @ApiImplicitParam(name = "userName", value = "会员姓名", dataType = "string", required = false),

    })
    public ResponseResult staffMemberRegister(@ApiIgnore TbUserInfo userInfo){

        return memberService.staffMemberRegister(userInfo);
    }

    /**
     * TODO 范欣宜 修改会员
     * @Author: 范欣宜
     * @Date: 2020/10/21 19:42
     * @param userInfo: 会员信息
     * @return: com.bw.common.utils.ResponseResult
     **/
    @PostMapping("updateMember")
    @ApiOperation(value="修改会员", notes="修改会员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "职员id", dataType = "int", required = true),
            @ApiImplicitParam(name = "age", value = "年龄", dataType = "int", required = false),
            @ApiImplicitParam(name = "sex", value = "性别", dataType = "int", required = false),
            @ApiImplicitParam(name = "email", value = "邮箱", dataType = "string", required = false),
            @ApiImplicitParam(name = "mobile", value = "会员手机号", dataType = "string", required = false),
            @ApiImplicitParam(name = "humanFaceUrl", value = "面部url", dataType = "string", required = false),
            @ApiImplicitParam(name = "idCard", value = "身份证号", dataType = "string", required = false),
            @ApiImplicitParam(name = "memberCode", value = "会员码", dataType = "string", required = false),
            @ApiImplicitParam(name = "realName", value = "会员真实姓名", dataType = "string", required = false),
            @ApiImplicitParam(name = "userName", value = "会员姓名", dataType = "string", required = false),
    })
    public ResponseResult updateStaffMember(@ApiIgnore TbUserInfo userInfo){

        return memberService.updateStaffMember(userInfo);
    }


    /**
     * TODO 范欣宜 手机号登录
     * @Author: 范欣宜
     * @Date: 2020/10/21 19:27
     * @param mobile: 手机号
     * @param verification: 验证码
     * @return: com.bw.common.utils.ResponseResult
     **/

    @PostMapping("phoneLogin")
    @ApiOperation(value="手机号登录", notes="手机号登录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mobile", value = "手机号",dataType = "String",required = true),
            @ApiImplicitParam(name = "verification", value = "验证码",dataType = "String",required = true),
    })
    public ResponseResult phoneLogin(String mobile,String verification){

        return memberService.phoneLogin(mobile,verification);
    }


    /**
     * TODO 范欣宜 获取验证码
     * @Author: 范欣宜
     * @Date: 2020/10/21 19:27
     * @param mobile: 手机号
     * @return: com.bw.common.utils.ResponseResult
     **/
    @PostMapping("/getVerification")
    @ApiOperation(value = "获取验证码", notes = "获取验证码")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mobile", value = "手机号", dataType = "String", required = true),
    })
    public ResponseResult getVerification(@RequestParam("mobile") String mobile){
        return memberService.getVerification(mobile);
    }

    /**
     * TODO 范欣宜 上传
     * @Author: 范欣宜
     * @Date: 2020/10/21 19:27
     * @return: com.bw.common.utils.ResponseResult
     **/
//    @PostMapping("upload")
//    public ResponseResult upload(MultipartFile file) {
//        return memberService.upload(file);
//    }

    @ApiOperation(value = "头像上传", notes = "头像上传")
    @PostMapping(value = "/uploadImg")
    public ResponseResult uploadImg(MultipartFile file) {
        return memberService.uploadImg(file);
    }


    /**
     * TODO 范欣宜 下载
     * @Author: 范欣宜
     * @Date: 2020/10/21 19:27
     **/
    @GetMapping("download/{path}")
    public void download(@PathVariable("path") String path, HttpServletResponse response) {
        memberService.download(path,response);
    }
}
